{extend name="Base/base"/}

{block name="body"}
<!-- 标题 -->
    <div class="main-title">
        <h2>
            商品-服务管理                    </h2>
    </div>

    <div style="margin-bottom: 10px;" class="hide" id="search_form">

        <style>
            .tb_search td{
                padding: 5px 10px;
            }
        </style>

        <div style="border-top:1px solid #ccc;border-bottom: 1px solid white"></div>
    </div>
    <!-- 按钮工具栏 -->
    <div class="with-padding">
        <div class="fl">

            <a href="{:url('',array('action'=>'add'))}" class="btn btn-ajax btn-success btn">新增商品</a>&nbsp;
            <button class="btn ajax-post btn" url="{:url('',array('action'=>'delete'))}" target-form="ids">删除</button>&nbsp;

            <!-- 选择框select -->
            <div style="float: right;">
                <style>
                    .oneselect{
                        display: inline-block;
                        margin-left: 10px;
                    }
                    .oneselect .title{
                        float: left;
                        line-height: 32px;
                    }
                    .oneselect .select_box{
                        float: left;
                        line-height: 32px;
                    }
                    .oneselect .select_box select{
                        min-width: 200px;
                    }
                </style>
                <form id="selectForm" method="get" action="{:url('')}" class="form-dont-clear-url-param">
                    <div class="oneselect">
                        <div class="title">分类查看</div>
                        <div class="select_box">
                            <select name="cat_id" data-role="select_text" class="form-control">
                                <option value="0" selected="">全部分类</option>
                                {foreach name="tag" item="c"}
                                <option value="{$c.id}">{$c.title}&nbsp;</option>
                                {/foreach}
                            </select>
                        </div>
                    </div><div class="oneselect">
                    <div class="title">显示模式</div>
                    <div class="select_box">
                        <select name="status" data-role="select_text" class="form-control">
                            <option value="0" selected="">正常</option>
                            <option value="1">禁用</option>                            </select>
                    </div>
                </div>
                </form>
            </div>
        </div>

    </div>


    <!-- 数据表格 -->
    <div class="with-padding" stype="width:auto; overflow: auto;">
        <table id="table-data" class="table table-bordered table-striped table-hover">
            <!-- 表头 -->
            <thead>
            <tr>
                <th class="row-selected">
                    <input class="checkbox check-all" type="checkbox">
                </th>
                <th>标题</th><th>图片</th><th>所属栏目</th><th>时间</th><th>排序</th><th>状态</th><th>操作
            </th>            </tr>
            </thead>

            <!-- 列表 -->
            <tbody>
            {foreach name="list" item="vo"}
            <tr>
                <td><input class="ids row-selected" type="checkbox" name="ids" value="{$vo.id}"></td>
                <td>{$vo.title}</td>
                <td>
                    {notempty name="vo.image"}
                    <img style="width:auto;max-width: 235px;"
                         src="{$vo['image']}" />
                    {/notempty}
                </td>
                <td>{$vo.cat_title}</td>
                <td>{$vo.create_time}</td>
                <td>{$vo.sort}</td>
                <td>{if condition="$vo['status'] == 0"}启用{else/}禁用{/if}</td>
                <td>
                    <a href="{:url('',array('action'=>'add','id'=>$vo['id']))}">更新内容</a>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
    <!-- 分页 -->
    <div class="with-padding">
        {$page}
    </div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
    $(function(){
        //点击排序
        $('.list_sort').click(function () {
            var url = $(this).attr('url');
            var ids = $('.ids:checked');
            var param = '';
            if (ids.length > 0) {
                var str = new Array();
                ids.each(function () {
                    str.push($(this).val());
                });
                param = str.join(',');
            }
            if (url != undefined && url != '') {
                window.location.href = url + '&ids=' + param;
            }
        });
        $('[data-role="select_text"]').change(function(){
            $('#selectForm').submit();
        });
        //模态弹窗
        $('[data-role="modal_popup"]').click(function(){
            var target_url=$(this).attr('modal-url');
            var data_title=$(this).attr('data-title');
            var target_form=$(this).attr('target-form');
            if(target_form!=undefined){
                //设置了参数时，把参数加入
                var form=$('.'+target_form);
                if (form.get(0) == undefined ) {
                    updateAlert('没有可操作数据。','danger');
                    return false;
                } else if (form.get(0).nodeName == 'FORM') {
                    query = form.serialize();
                } else if (form.get(0).nodeName == 'INPUT' || form.get(0).nodeName == 'SELECT' || form.get(0).nodeName == 'TEXTAREA') {
                    query = form.serialize();
                } else {
                    query = form.find('input,select,textarea').serialize();
                }
                if(!query.length && $(this).attr('can_null') != 'true'){
                    updateAlert('没有可操作数据。','danger');
                    return false;
                }
                target_url=target_url+'&'+query;
            }
            var myModalTrigger = new $.zui.ModalTrigger({
                'type':'ajax',
                'url':target_url,
                'title':data_title
            });
            myModalTrigger.show();
        });
        $('.tox-confirm').click(function(e){
            var text = $(this).attr('data-confirm');
            var result = confirm(text);
            if(result) {
                return true;
            } else {
                e.stopImmediatePropagation();
                e.stopPropagation();
                e.preventDefault();
                return false;
            }
        })
    });
</script>
{/block}